﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using System.Windows.Forms;
using System.Drawing;

namespace MNNUTEM
{
    class crudLote
    {



        private Conexion cn = new Conexion();
        String query;
        private mensaje msj;

        public void Insert(TextBox idLote, string ingresoLote, string caducaLote, TextBox estadoLote, TextBox cantidadLote, TextBox comentarioLote)
        {
            try
            {
                query = "insert into Lote (idLote, ingresoLote,caducaLote,estadoLote,cantidadLote,comentarioLote) values ('" + idLote.Text + "','" + ingresoLote + "','" + caducaLote+ "','" + estadoLote.Text + "','" + cantidadLote.Text + "','" + comentarioLote.Text + "')";
                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                cn.conn().Close();
                msj = new mensaje("Usuario Ingresado con éxito.", 1300, Color.Green);

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }



        }
        public void Delete(int ID)
        {

            try
            {
                query = "delete from Usuario where rutUsuario='" + ID + "'";
                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                myCommand.Connection.Open();
                myCommand.ExecuteNonQuery();
                cn.conn().Close();
                msj = new mensaje("Acción realizada con éxito.", 1300, Color.Green);

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }


        }
        private void Set()
        { }

        public DataTable Consultation(string consultation)
        {

            try
            {


                query = consultation;
                MySqlCommand myCommand = new MySqlCommand(query, cn.conn());
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = myCommand;
                DataTable dtable = new DataTable();
                sda.Fill(dtable);


                return dtable;

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception("Se ha producido un error:", ex);
            }

        }


    }
}
